using admin.core.Entities;

namespace admin.core.Entities.App;

public class AppUser : EntityBase
{
    public string UserName { get; set; } = null!;
    public string PassWord { get; set; } = null!;
    public string? Phone { get; set; }
    public string? Email { get; set; }

    public string Salt { get; set; } = null!;

    public ICollection<AppRole> Roles { get; set; } = new List<AppRole>();

    public void AssignRole(AppRole role)
    {
        if (!Roles.Contains(role))
            Roles.Add(role);
    }

    public void RemoveRole(AppRole role)
    {
        if (Roles.Contains(role))
            Roles.Remove(role);
    }

    public bool HasPermission(string permissionCode)
    {
        return Roles.Any(r => r.HasPermission(permissionCode));
    }
}